package com.loe.test

import android.os.Bundle
import com.loe.mvp.BaseActivity
import com.loe.mvp.ext_app.afterFinish
import com.loe.mvp.ext_app.setStatusAlpha
import com.loe.mvp.ext_app.transInAlpha
import com.loe.mvp.ext_java.DelayTask
import com.loe.mvp.ext_java.delay
import com.loe.ui.LoeUI
import com.loe.ui.openUI

class SplashActivity : BaseActivity()
{
    private var delayTask: DelayTask? = null

    private var isJumped = false

    override fun onCreate(savedInstanceState: Bundle?)
    {
        super.onCreate(savedInstanceState)
        setStatusAlpha(false)
        setContentView(R.layout.activity_splash)

        prepJump { openUI("TestViewPager").afterFinish { transInAlpha() } }
    }

    private fun prepJump(onPrep: () -> Unit)
    {
        fun jump()
        {
            if (isJumped) return
            isJumped = true
            delayTask?.stop()

            onPrep()
        }

        LoeUI.loadPackJs { delay(500) { jump() } }
        delayTask = delay(2000)
        {
            jump()
        }
    }
}